<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link rel="stylesheet" href="/assets/layim/plugins/CropBox/css/style.css?v=1" type="text/css"/>
</head>
<body>
<div class="container">
    <div class="imageBox">
        <div class="thumbBox"></div>
        <div class="spinner" style="display: none">加载中...</div>
    </div>
    <div class="action">
        <div class="new-contentarea tc">
            <a href="javascript:void(0)" class="upload-img">
                <label>保存图片</label>
            </a>
        </div>
        <input type="button" id="btnCrop" class="Btnsty_peyton" value="裁切">
        <input type="button" id="btnZoomIn" class="Btnsty_peyton" value="+">
        <input type="button" id="btnZoomOut" class="Btnsty_peyton" value="-">
    </div>
    <div class="cropped"></div>
</div>
<script src="/assets/layim/plugins/CropBox/js/jquery-1.11.0.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/assets/layim/plugins/CropBox/js/cropbox.js"></script>
<script type="text/javascript">
    $(function () {
        var currentData = "";
        var cropper = $('.imageBox').cropbox({thumbBox: '.thumbBox', spinner: '.spinner', imgSrc: '{{imgurl}}'});
        $('#btnCrop').on('click', function () {
            currentData = cropper.getDataURL();
            var cropbox = $('.cropped');
            cropbox.html('')
                .append('<img src="' + currentData + '" align="absmiddle" class="img-64" ><p>64px*64px</p>')
                .append('<img src="' + currentData + '" align="absmiddle" class="img-128"><p>128px*128px</p>')
                .append('<img src="' + currentData + '" align="absmiddle" class="img-180"><p>180px*180px</p>');
        });
        $('#btnZoomIn').click(function () {
            cropper.zoomIn();
        });
        $('#btnZoomOut').click(function () {
            cropper.zoomOut();
        });
        $('.upload-img').on('click', function () {
            if (currentData == "") return parent.layui.layer.msg("请先裁剪图片");
            $.post(top.API.cropbox, {imgcode: currentData,old:"{{imgurl}}"}, function (data) {
                if (data.errcode) return parent.layui.layer.msg(data.message);
                parent.layui.jquery(".dkuang1").css("background-image", "url(" + data.data + ")");
                parent.layui.jquery("#L_avatar").val(data.data);
                parent.layui.layer.closeAll("iframe");   //关闭父级打开的本体窗口
            });
        });
    });
</script>
</body>
</html>